package io.scnb.lesson003.demo1.test3;

import org.springframework.context.ApplicationEventPublisher;
import org.springframework.context.ApplicationEventPublisherAware;
import org.springframework.stereotype.Component;

@Component
public class UserRegisterService implements ApplicationEventPublisherAware {
    
    private ApplicationEventPublisher applicationEventPublisher;

    /**
     * 负责用户注册以及发布事件的功能
     */
    public void registerUser(String userName) {
        // 用户注册
        System.out.println(String.format("用户【%s】注册成功", userName));
        // 发布注册成功事件
        this.applicationEventPublisher.publishEvent(new UserRegisterEvent(this, userName));
    }
    
    @Override
    public void setApplicationEventPublisher(ApplicationEventPublisher applicationEventPublisher) {
        this.applicationEventPublisher = applicationEventPublisher;
    }
}
